package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.Unknown;

/**
 * @author tzp
 * @since 2020/10/30
 */
public class LC21_1 implements Unknown {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        if(l1 == null) return l2;
        else if(l2 == null) return l1;
        ListNode dummy = new ListNode(0);
        ListNode curr = dummy;
        while(l1 != null && l2!= null){
            if(l1.val <= l2.val){
                curr.next = l1;
                l1 = l1.next;
            }else {
                curr.next = l2;
                l2 = l2.next;
            }
            curr = curr.next;
        }
        curr.next = l1 == null? l2:l1;
        return dummy.next;
    }
    public static void main(String[] args) {
        System.out.println(new LC21_1());
    }
}
